package constant.milk.cashbook.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;

public class MainFanActivity extends SuperActivity
{
	public static final String MAIN_FAN_DATA = "MAIN_FAN_DATA";
	
	private View fanInView;
	private View fanOutView;
	private View fanReturnView;
	private View fanReceiveView;
	
	private RadioButton faninRadio;
	private RadioButton fanOutRadio;
	private RadioButton fanReturnRadio;
	private RadioButton fanReceiveRadio;
	
	private Button checkButton;
	
	private String typeStr;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main_fan_activity);
		
		setTitle("부채종류");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		fanInView = findViewById(R.id.mainFanInView);
		fanOutView = findViewById(R.id.mainFanOutView);
		fanReturnView = findViewById(R.id.mainFanReturnView);
		fanReceiveView = findViewById(R.id.mainFanReceiveView);
		
		faninRadio = (RadioButton) findViewById(R.id.mainFanInRadio);
		fanOutRadio = (RadioButton) findViewById(R.id.mainFanOutRadio);
		fanReturnRadio = (RadioButton) findViewById(R.id.mainFanReturnRadio);
		fanReceiveRadio = (RadioButton) findViewById(R.id.mainFanReceiveRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		fanInView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setFanInRadio();
			}
		});
		
		fanOutView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setFanOutRadio();
			}
		});
		
		fanReturnView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setFanReturnRadio();
			}
		});
		
		fanReceiveView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setFanReceiveRadio();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(MAIN_FAN_DATA, typeStr);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String data = intent.getStringExtra(MAIN_FAN_DATA);
		
		if (data.equals(getString(R.string.fanIn)))
		{
			setFanInRadio();
		}
		else if (data.equals(getString(R.string.fanOut)))
		{
			setFanOutRadio();
		}
		else if (data.equals(getString(R.string.fanReturn)))
		{
			setFanReturnRadio();
		}
		else if (data.equals(getString(R.string.fanReceive)))
		{
			setFanReceiveRadio();
		}
		else 
		{
			setFanInRadio();
		}
	}

	private void setFanInRadio()
	{
		faninRadio.setChecked(true);
		fanOutRadio.setChecked(false);
		fanReturnRadio.setChecked(false);
		fanReceiveRadio.setChecked(false);
		typeStr = getResources().getString(R.string.fanIn);
	}
	
	private void setFanOutRadio()
	{
		faninRadio.setChecked(false);
		fanOutRadio.setChecked(true);
		fanReturnRadio.setChecked(false);
		fanReceiveRadio.setChecked(false);
		typeStr = getResources().getString(R.string.fanOut);
	}
	
	private void setFanReturnRadio()
	{
		faninRadio.setChecked(false);
		fanOutRadio.setChecked(false);
		fanReturnRadio.setChecked(true);
		fanReceiveRadio.setChecked(false);
		typeStr = getResources().getString(R.string.fanReturn);
	}
	
	private void setFanReceiveRadio()
	{
		faninRadio.setChecked(false);
		fanOutRadio.setChecked(false);
		fanReturnRadio.setChecked(false);
		fanReceiveRadio.setChecked(true);
		typeStr = getResources().getString(R.string.fanReceive);
	}
	
	@Override
	protected void tipButton()
	{
	}

}
